package br.puc.casas.ca;

import javax.swing.JFrame;

import org.generation5.demos.DictyosteliumCA;
import org.generation5.swing.VisualizationPanel;

public class MyFrame extends JFrame implements Runnable {
	private static final long serialVersionUID = 8109020979072046808L;

	private VisualizationPanel panel;

	private DictyosteliumCA dictyosteliumCA;

	public MyFrame() {
	}

	public void init() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		panel = new VisualizationPanel();
		panel.setAntiAliasing(true);
		add(panel);

		dictyosteliumCA = new DictyosteliumCA(100, 100);
		dictyosteliumCA.init();
		panel.setContent(dictyosteliumCA);
	}

	public void run() {
		try {
			while (true) {
				dictyosteliumCA.doStep();
				panel.repaint();
				Thread.sleep(100);
			}
		} catch (InterruptedException e) {
		}
	}

	public static void main(String[] args) {
		MyFrame frame = new MyFrame();
		frame.init();
		frame.setSize(300, 300);
		frame.setVisible(true);

		Thread anim = new Thread(frame);
		anim.setDaemon(true);
		anim.start();
	}
}
